package com.sky.mapper;

import com.sky.entity.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;

import java.util.Map;

/**
 * @Description
 * @Author shh
 * @Date 2025-10-11
 */
@Mapper
public interface UserMapper {
    /**
     * 根据openid查询用户
     * @param openid
     * @return
     */
    @Select("select * from user where openid = #{openid}")
    User selectByOpenid(String openid);

    /**
     * 插入用户
     * @param user
     */
    @Options(useGeneratedKeys = true,keyProperty = "id")
    @Insert("insert into user (openid,name,create_time) values (#{openid},#{name},#{createTime})")
    void insert(User user);
    /**
     * 根据id查询用户
     * @param currentId
     * @return
     */
    @Select("select * from user where id = #{currentId}")
    User selectById(Long currentId);
    /**
     * 查询新增用户数量
     * @param map
     * @return
     */
    @Select("select count(id) from user where create_time between #{beginTime} and #{endTime}")
    Integer selectNewUserCount(Map map);
    /**
     * 查询当日及其之前的所有用户数量，
     * @param map
     * @return
     */
    @Select("select count(id) from user where create_time <= #{endTime}")
    Integer selectAllUserCount(Map map);

}
